package org.lc.stk.web.dto.cengci;

import io.swagger.v3.oas.annotations.media.Schema;

@Schema(description = "培养层次查询条件")
public class CengciQuery {
    
    @Schema(description = "培养层次编码(模糊匹配)", example = "B")
    private String code;
    
    @Schema(description = "培养层次名称(模糊匹配)", example = "本")
    private String name;
    
    @Schema(description = "是否包含已删除记录", example = "false")
    private Boolean includeDeleted = false;
    
    @Schema(description = "排序字段(code/name/orderNum/createTime)", example = "orderNum")
    private String sortBy = "orderNum";
    
    @Schema(description = "排序方式(asc/desc)", example = "asc")
    private String sortDirection = "asc";

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Boolean getIncludeDeleted() {
        return includeDeleted;
    }

    public void setIncludeDeleted(Boolean includeDeleted) {
        this.includeDeleted = includeDeleted;
    }

    public String getSortBy() {
        return sortBy;
    }

    public void setSortBy(String sortBy) {
        // 验证排序字段
        if (sortBy != null && !isValidSortField(sortBy)) {
            throw new IllegalArgumentException("Invalid sort field: " + sortBy);
        }
        this.sortBy = sortBy;
    }

    public String getSortDirection() {
        return sortDirection;
    }

    public void setSortDirection(String sortDirection) {
        // 验证排序方向
        if (sortDirection != null && 
            !sortDirection.equalsIgnoreCase("asc") && 
            !sortDirection.equalsIgnoreCase("desc")) {
            throw new IllegalArgumentException("Sort direction must be either 'asc' or 'desc'");
        }
        this.sortDirection = sortDirection.toLowerCase();
    }

    private boolean isValidSortField(String field) {
        return field.equals("code") || 
               field.equals("name") || 
               field.equals("orderNum") || 
               field.equals("createTime");
    }
}